package club.baimahu.pencil.domain.entity.discount;

import club.baimahu.pencil.domain.entity.order.CommodityList;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class DiscountManager {

    List<DiscountStrategy> discountStrategyList;

    CommodityList commodityList;

    public BigDecimal getOptimalPayment(){
        BigDecimal minShouldPay = commodityList.totalMoney();
        for(DiscountStrategy discountStrategy:discountStrategyList){
            BigDecimal shouldPay = discountStrategy.discount(commodityList);
            if(shouldPay.doubleValue() < minShouldPay.doubleValue()){
                minShouldPay = shouldPay;
            }
        }
        return minShouldPay;
    }

}
